package com.seaboxdata.service.impl;

import com.seaboxdata.dao.MysqlDao;
import com.seaboxdata.entity.MysqlDeleteVo;
import com.seaboxdata.entity.OldStrategyConfig;
import com.seaboxdata.service.MysqlDataAgeService;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author
 * @create 2021-01-29 10:00
 **/

@Service
public class MysqlDataAgeServiceImpl implements MysqlDataAgeService {

    @Autowired
    private MysqlDao mysqlDao;

    @Override
    public void dataAge(OldStrategyConfig config) {
        //获取最新的时间,然后确定保留的时间
        Date latestDate = mysqlDao.getLatestDate(config);

        Date deleteDate = DateUtils.addDays(latestDate, -Integer.valueOf(config.getPeriod()));

        MysqlDeleteVo mysqlDeleteVo = new MysqlDeleteVo();
        mysqlDeleteVo.setConfig(config);
        mysqlDeleteVo.setDeleteDate(deleteDate);
        mysqlDao.dataAge(mysqlDeleteVo);
    }
}
